﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using SAPPDI.Entitys;
using TestImpresion.Clases.Comunes;

namespace TestImpresion.Controles
{
    public partial class EncuadernadoDinamicoRustico : UserControl
    {
        private readonly DependencyProperty _solapa1Property =
DependencyProperty.Register("SolapaUno", typeof(double), typeof(EncuadernadoDinamicoRustico), new PropertyMetadata(new Double()));

        [System.ComponentModel.Category("User properties")]
        [System.ComponentModel.Description("User SolapaUno")]
        public double SolapaUno
        {
            get { return (double)GetValue(_solapa1Property); }
            set
            {
                SetValue(_solapa1Property, value);
            }
        }

        private readonly DependencyProperty _solapa2Property =
DependencyProperty.Register("SolapaDos", typeof(double), typeof(EncuadernadoDinamicoRustico), new PropertyMetadata(new Double()));

        [System.ComponentModel.Category("User properties")]
        [System.ComponentModel.Description("User SolapaDos")]
        public double SolapaDos
        {
            get { return (double)GetValue(_solapa2Property); }
            set
            {
                SetValue(_solapa2Property, value);
            }
        }

        private readonly DependencyProperty _voladoProperty =
DependencyProperty.Register("Volado", typeof(double), typeof(EncuadernadoDinamicoRustico), new PropertyMetadata(new Double()));

        [System.ComponentModel.Category("User properties")]
        [System.ComponentModel.Description("User Volado")]
        public double Volado
        {
            get { return (double)GetValue(_voladoProperty); }
            set
            {
                SetValue(_voladoProperty, value);
            }
        }

        private readonly DependencyProperty _soloHorizontalProperty =
DependencyProperty.Register("SoloHorizontal", typeof(bool), typeof(EncuadernadoDinamicoRustico), new PropertyMetadata(new Boolean()));

        [System.ComponentModel.Category("User properties")]
        [System.ComponentModel.Description("User SoloHorizontal")]
        public bool SoloHorizontal
        {
            get { return (bool)GetValue(_soloHorizontalProperty); }
            set
            {
                SetValue(_soloHorizontalProperty, value);
            }
        }

        

        public EncuadernadoDinamicoRustico()
        {
            InitializeComponent();
            btnsoloHor.IsChecked = true;
        }

        private void ToggleButton_OnChecked(object sender, RoutedEventArgs e)
        {
            var toogle = (ToggleButton)sender;
            Utiles.UncheckElementos(toogle, this.LayoutRoot.Children);
            SoloHorizontal = toogle.Name == "btnsoloHor";            
        }

        private void BtnUp_OnClick(object sender, RoutedEventArgs e)
        {
            double insertos;
            var esnumero = double.TryParse(this.txtSolapa1.Text, out insertos);
            this.txtSolapa1.Text = esnumero ? (insertos + 1).ToString() : "0";
        }

        private void Btndown_OnClick(object sender, RoutedEventArgs e)
        {
            double insertos;
            var esnumero = double.TryParse(this.txtSolapa1.Text, out insertos);
            this.txtSolapa1.Text = esnumero && insertos > 0 ? (insertos - 1).ToString() : "0";
        }

        private void BtnUp2a_OnClick(object sender, RoutedEventArgs e)
        {
            double insertos;
            var esnumero = double.TryParse(this.txtSolapa2.Text, out insertos);
            this.txtSolapa2.Text = esnumero ? (insertos + 1).ToString() : "0";
        }

        private void Btndown2a_OnClick(object sender, RoutedEventArgs e)
        {
            double insertos;
            var esnumero = double.TryParse(this.txtSolapa2.Text, out insertos);
            this.txtSolapa2.Text = esnumero && insertos > 0 ? (insertos - 1).ToString() : "0"; 
        }

        private void BtnUpvolado_OnClick(object sender, RoutedEventArgs e)
        {
           double insertos;
           var esnumero = double.TryParse(this.textBoxvolado.Text, out insertos);
           this.textBoxvolado.Text = esnumero ? (insertos + 1).ToString() : "0";
        }

        private void Btndownvolado_OnClick(object sender, RoutedEventArgs e)
        {
            double insertos;
            var esnumero = double.TryParse(this.textBoxvolado.Text, out insertos);
            this.textBoxvolado.Text = esnumero && insertos > 0 ? (insertos - 1).ToString() : "0"; 
        }
    }
}
